﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LardonPokerSimulator.Model.Deck
{
    public class Cards
    {
        internal Random random = new Random();
        internal Card[] cardArray = null;

        public Cards()
        { }

        internal Cards(int randomSeed)
        {
            random = new Random(randomSeed);
        }

        internal void GenerateFrenchDeck()
        {
            List<Card> cards = new List<Card>();
            Array suits = Enum.GetValues(typeof(Suit));

            foreach (Suit s in suits)
            {
                for (short i = 1; i <= 13; i++)
                {
                    cards.Add(new Card(i, s));
                }
            }

            cardArray = cards.ToArray();
        }

        public Card PickRandomCard()
        {
            //Get a list of non-used card.
            List<Card> subListe = this.cardArray.Where(cl => !cl.IsUsed).ToList();

            //Select one random card in this list.
            Card randomCard = subListe.ElementAt(this.random.Next(subListe.Count()));

            //Mark card as used
            randomCard.IsUsed = true;

            return randomCard;
        }
    }
}
